#include <stdio.h>
#include "pico/stdlib.h"
#include "pico/binary_info.h"
#include "hardware/spi.h"

#include "wizchip_conf.h"
#include "w5500.h"
#include "w5500_spi.h"
#include "socket.h"
#include "loopback.h"
#include "sntp.h"


/* Socket */
#define SOCKET_SNTP 0
/* Timeout */
#define RECV_TIMEOUT (1000 * 10) // 10 seconds

/* Timezone */
#define TIMEZONE 39 // China


#define ETHERNET_BUF_MAX_SIZE (1024 * 2)

void network_init(void);

wiz_NetInfo net_info = {
    .mac = {0x00, 0x08, 0xdc, 0x16, 0xed, 0x2e},
    .ip = {192, 168, 124, 10},
    .sn = {255, 255, 255, 0},
    .gw = {192, 168, 124, 1},
    .dns = {8, 8, 8, 8},
    .dhcp = NETINFO_STATIC};
wiz_NetInfo get_info;
static uint8_t ethernet_buf[ETHERNET_BUF_MAX_SIZE] = {0,};
static uint8_t destip[4]={192,168,124,2};
static uint16_t destport = 8080;
static uint16_t local_port =8000;
static uint8_t g_sntp_server_ip[4] = {203, 107, 6, 88}; 

int main()                                                          
{   
    /* Initialize */
    
    uint32_t start_ms = 0;
    datetime time={0};
    stdio_init_all();
    sleep_ms(2000);
    network_init();
    SNTP_init(SOCKET_SNTP,g_sntp_server_ip,TIMEZONE,ethernet_buf);
    while(1)
    {
       
       SNTP_run(&time);
       
        sleep_ms(1000);
        printf(" %d-%d-%d, %d:%d:%d\n", time.yy, time.mo, time.dd, time.hh, time.mm, time.ss);
      
    }
      
}

void network_init(void)
{
   
    wizchip_initialize(); 
    wizchip_setnetinfo(&net_info);
    print_network_information(get_info);

}